#pragma once
#include "global.h"

#define WIDTHBYTES(bits)    (((bits) + 31) / 32 * 4)

class  JpegFile
{
public:
	unsigned long m_lWidth;
	unsigned long m_lHeight;
	unsigned long  m_dwPoint;
	DWORD m_dwOutMaxSize;
	BYTE * m_lpOutBuffer;
	BYTE * m_lpPreData;
	DWORD m_dwScreenMaxSize;
	BYTE * m_lpScreenBuffer;
	DWORD m_dwFrame;

	JpegFile(void);
public:
	~JpegFile(void);


	BYTE *BMPtoFix(unsigned char * lpData, 
		unsigned long *lWidth ,
		unsigned long *lHeight, 
		unsigned long *lHeadSize, 
		unsigned long *lSize);

	BYTE *FixtoBMP(unsigned char * lpInData, 
		unsigned long lWidth ,
		unsigned long lHeight, 
		unsigned char * lpHeadData,
		unsigned long lHeadSize, 
		unsigned long w, 
		unsigned long h) ;

	BYTE * LoadBMP(LPSTR lpData, unsigned long *lWidth ,unsigned long *lHeight) ;

	BOOL RGBToJpegFile(BYTE *dataBuf,
		BYTE *outBuf,
		UINT widthPix,
		UINT height,
		BOOL color, 
		int quality,
		unsigned long *size);


	BYTE * JpegFileToRGB(BYTE *inBuf,
		unsigned long size,
		UINT *width,
		UINT *height);

	void JpegFile::DeletePreData();

	 BYTE * MakeDwordAlignedBuf(BYTE *dataBuf,
		UINT widthPix,				// pixels!!
		UINT height,
		UINT *uiOutWidthBytes);		// bytes!!!

	 BOOL VertFlipBuf(BYTE  * inbuf, 
		 UINT widthBytes, 
		 UINT height);

	 BOOL BGRFromRGB(BYTE *buf, UINT widthPix, UINT height);

	 BYTE * MovetoBuf(BYTE *dataBuf,
		 TRect *prcRect,				// pixels!!
		 UINT widthNew,
		 UINT heightNew);		// bytes!!!

	 BOOL MakeGrayScale(BYTE *buf, UINT widthPix, UINT height, BOOL trun);
};
